package com.cocotea.valid.factory;

import com.cocotea.valid.service.IValidDispatcher;
import com.cocotea.valid.service.impl.ValidDispatcherImpl;

public class ValidHandlerFactory {
    private static IValidDispatcher validDispatcher;

    public static IValidDispatcher getInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        IValidDispatcher validHandler;
        if (!"".equals(className)) {
            Object instance = Class.forName(className).newInstance();
            validHandler = (IValidDispatcher)instance;
        } else {
            if (validDispatcher == null) {
                validDispatcher = new ValidDispatcherImpl();
            }
            validHandler = validDispatcher;
        }
        return validHandler;
    }
}
